package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 游记
 */
@Setter
@Getter
public class Travel extends BaseDomain{
    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_AUDIT = 1;//待审核
    public static final int STATE_RELEASE = 2;//发布
    public static final int STATE_REJECT = -1;//拒绝

    //标题
    private String title;
    //旅游时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;
    //人均消费
    private String perExpends;
    //旅游天数
    private Integer days;
    //和谁旅游
    private Integer person;
    //作者
    private User author;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date releaseTime;
    //是否公开
    private Boolean isPublic = false;
    //旅游地点
    private Region place;
    //封面
    private String coverUrl;
    //最后更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;
    //状态
    private Integer state=STATE_COMMON;
    //游记内容
    private TravelContent travelContent;

    public String getStateName(){
        String temp = "草稿";
        if(state==STATE_AUDIT){
            temp = "待审核";
        }else if(state==STATE_RELEASE){
            temp = "已发布";
        }else if(state==STATE_REJECT){
            temp = "已拒绝";
        }
        return temp;
    }

    public String getPersonName(){
        String temp = "一个人的旅行";
        if(person==2){
            temp = "和父母";
        }else if(person==3){
            temp = "和朋友";
        }else if(person==4){
            temp = "和同事";
        }else if(person==5){
            temp = "和爱人";
        }else if(person==6){
            temp = "和其他";
        }
        return temp;
    }


    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        //将需要的数据添加到map集合中
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("title",title);
        if(author!=null){
            map.put("authorId",author.id);
        }
        //将map集合转换成json格式的字符串,再返回
        return JSON.toJSONString(map);
    }

}